#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
vector<int>side[200002];
int point[200002];
void dfs(int x){
    point[x]=1;
    cout<<x<<" ";
    for(int i=0;i<side[x].size();i++){
        if(!point[side[x][i]])dfs(side[x][i]);
    }
}
int main(){
    int n,e;
    cin>>n>>e;
    for(int i=1;i<=e;i++){
        int a,b;
        cin>>a>>b;
        side[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        sort(side[i].begin(),side[i].end());
    }
    for(int i=0;i<n;i++){
        if(!point[i])dfs(i);
    }
    return 0;
}